
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.Except;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Except entities.
 * 
 */
@Repository("ExceptDAO")

@Transactional
public class ExceptDAOImpl extends AbstractJpaDao<Except> implements ExceptDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			Except.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new ExceptDAOImpl
	 *
	 */
	public ExceptDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findExceptByBarcode
	 *
	 */
	@Transactional
	public Set<Except> findExceptByBarcode(String barcode) throws DataAccessException {

		return findExceptByBarcode(barcode, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByBarcode
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findExceptByBarcode(String barcode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findExceptByBarcode", startResult, maxRows, barcode);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * JPQL Query - findExceptById
	 *
	 */
	@Transactional
	public Except findExceptById(Integer id) throws DataAccessException {

		return findExceptById(id, -1, -1);
	}

	/**
	 * JPQL Query - findExceptById
	 *
	 */

	@Transactional
	public Except findExceptById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findExceptById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.Except) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findExceptByReportTime
	 *
	 */
	@Transactional
	public Set<Except> findExceptByReportTime(java.util.Calendar reportTime) throws DataAccessException {

		return findExceptByReportTime(reportTime, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByReportTime
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findExceptByReportTime(java.util.Calendar reportTime, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findExceptByReportTime", startResult, maxRows, reportTime);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * JPQL Query - findExceptByMemo
	 *
	 */
	@Transactional
	public Set<Except> findExceptByMemo(String memo) throws DataAccessException {

		return findExceptByMemo(memo, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByMemo
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findExceptByMemo(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findExceptByMemo", startResult, maxRows, memo);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * JPQL Query - findExceptByPrimaryKey
	 *
	 */
	@Transactional
	public Except findExceptByPrimaryKey(Integer id) throws DataAccessException {

		return findExceptByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByPrimaryKey
	 *
	 */

	@Transactional
	public Except findExceptByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findExceptByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.Except) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findExceptByBarcodeContaining
	 *
	 */
	@Transactional
	public Set<Except> findExceptByBarcodeContaining(String barcode) throws DataAccessException {

		return findExceptByBarcodeContaining(barcode, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByBarcodeContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findExceptByBarcodeContaining(String barcode, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findExceptByBarcodeContaining", startResult, maxRows, barcode);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * JPQL Query - findExceptByMemoContaining
	 *
	 */
	@Transactional
	public Set<Except> findExceptByMemoContaining(String memo) throws DataAccessException {

		return findExceptByMemoContaining(memo, -1, -1);
	}

	/**
	 * JPQL Query - findExceptByMemoContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findExceptByMemoContaining(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findExceptByMemoContaining", startResult, maxRows, memo);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllExcepts
	 *
	 */
	@Transactional
	public Set<Except> findAllExcepts() throws DataAccessException {

		return findAllExcepts(-1, -1);
	}

	/**
	 * JPQL Query - findAllExcepts
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Except> findAllExcepts(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllExcepts", startResult, maxRows);
		return new LinkedHashSet<Except>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Except entity) {
		return true;
	}
}
